﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InfraWEB.BLL;
using InfraWEB.Comum.Enum;

namespace InfraWEB.UI
{
    public partial class ItemEstoqueNovo : Base
    {
        protected void Page_Load(object sender, EventArgs e)
        {
			CheckIfUsuarioIsLogged();
			CheckIfUsuarioHasAccessPermission(int.Parse(Enumeration.TipoUsuarioName.EquipeAdministrativaIndex));
			if (!Page.IsPostBack)
            {
                CarregarTipos();
            }
        }
        private void CarregarTipos()
        {
            ddlCategory.Items.Add(new ListItem(
                Enumeration.CategoriaItemEstoqueName.Alimenticio,
                Enumeration.CategoriaItemEstoqueName.AlimenticioIndex) { Selected = true });
            ddlCategory.Items.Add(new ListItem(
                Enumeration.CategoriaItemEstoqueName.Limpeza,
                Enumeration.CategoriaItemEstoqueName.LimpezaIndex));
            ddlCategory.Items.Add(new ListItem(
                Enumeration.CategoriaItemEstoqueName.MaterialEscritorio,
                Enumeration.CategoriaItemEstoqueName.MaterialEscritorioIndex));
        }

        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            ItemEstoque item = new ItemEstoque();
            string name = txtName.Text;
            int minimum = int.Parse(txtMinimum.Text);
            int critical = int.Parse(txtCritical.Text);
            string unit = txtUnit.Text;
            int quantity = int.Parse(txtQuantity.Text);
            int category = int.Parse(ddlCategory.Text);

            item.RecordItemEstoque(name, minimum, critical, unit, quantity, category);
            lblMensagem.Visible = false;
            lblMensagem.Text = "";
            Context.Session["ItemRegisterStatus"] = "true";
            Response.Redirect("~/ItemEstoqueLista.aspx");
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ItemEstoqueLista.aspx");
        }
    }
}
